import * as actions from '../actions/quote.action';
import {Quote} from "../domain/quote.model";
export interface State{
  quote:Quote;
};
export const initialState:State ={
  quote:{
  cn:"如果你能将你的技能变为你的本能,那么你将天下无敌",
  en:"If you can make your skills into instinct ,you will be unbeatable.",
  pic:"assets/img/quotes/5.jpg"
  }
};
export function reducer(state=initialState,action:actions.Actions):State{
  switch (action.type) {
    case actions.ActionTypes.LOAD_SUCCESS:{
      console.log(state);
      console.log({...state});
      console.log({...state, quote: <Quote> action.payload});
      return {...state, quote: <Quote> action.payload};
      //相当于Object.assign({},state,{quote:action.payload});
    }
    case actions.ActionTypes.LOAD_FAIL:
    default:{
      return state as State
    }
  }
}
export const getQuote = (state:State)=>state['quote'];

